<?php
// Fonction de surlignage
function highlight($field){
	$chaine = $_GET['s'];
	$chaine_r = utf8_decode ( $chaine );
	$value2 = utf8_decode ( $field );
	$chaine_r = preg_replace ("/\\W/",".",$chaine_r);
	$value1 = preg_replace("/($chaine_r)/i", '<span class="highlight">$1</span>', $value2);
	$field = utf8_encode($value1);
	return $field;
}

// Résultats et navigation du haut
if(isset($itemNumber)){
	echo '<table summary="results" style="padding-bottom:1em;"><tr><td class="roundBox">'."\n";
	echo '<span class="resultNumber">'.$itemNumber.'</span> notice(s)'."\n";
	echo 'sur <span class="resultNumber">'.$status['totalResults'].'</span>'."\n";
	echo '</td>'."\n";
	echo '<td>&nbsp;</td>';
	echo '<td class="roundBox">'."\n";
	echo $simpleNavBar;
	echo '</td></tr></table>'."\n";
}
$itemDate = '';
echo '<div class="results">'."\n";

// Pour chaque ligne
foreach($items as $key=>$value){
	//print_r($value);
	// Affichage Année
	if($value['yr']!=$itemDate) {
		$itemDate = $value['yr'];
		echo '<div class="fieldYr"><a href="?a=on&amp;yr='.$value['yr'].'&amp;action=go">'.$value['yr'].'</a></div>'."\n";
	}


	// Affichage notice
	$display = '<div class="notice">'."\n";

	// Calcul des URL pour le titre et les champs myrl et url
	$urlMyrl='';
	$libMyrl='';
	$titleMyrl='';
	$urlUrl='';
	$titleLink='';
	$urlTitle='';
	if ($value['censor']!=true){
		// Calcul de $urlMyrl et $libMyrl
		if(!empty($value['myrl'])){
			$extension=substr(strrchr($value['myrl'],'.'),1) ;
			if ($extension=='pdf') {$urlMyrl = 'http://www.univ-nancy2.fr/poincare/bhp/pdf/'.$value['myrl'];$libMyrl = '<span class="pdfLogo">&nbsp;</span>';}
			elseif ($extension=='xml') {$urlMyrl = 'http://www.univ-nancy2.fr/poincare/bhp/'.$value['myrl'];$libMyrl = 'XML';}
			elseif ($extension=='html') {$urlMyrl = 'http://www.univ-nancy2.fr/poincare/bhp/'.$value['myrl'];$libMyrl = 'HTML';}
			else {$libMyrl = $value['myrl'].', ';}
			$titleMyrl='Accès au texte intégral via AHP';
		}
		// Calcul de $urlUrl
		if(!empty($value['url'])){
			// Gestion des & pour un code valide
			$urlUrl = preg_replace("/\&/","&amp;",$value['url']);
			$domain = explode('/', $value['url']);
			$titleLink='Accès au texte intégral via '.$domain[2];
		}
		// Calcul de $urlTitle pour le titre
		if(!empty($urlMyrl)) {$urlTitle=$urlMyrl;$titleTitle=$titleMyrl;}
		elseif(!empty($value['url'])) {$urlTitle=$urlUrl;$titleTitle=$titleLink;}
	}


	// Titre
	if(!empty($value['bk']) and !empty($value['art'])) $display .= '<span class="docType">[Chapitre]</span> ';
	if(!empty($value['bk']) and empty($value['art'])) $display .= '<span class="docType">[Livre]</span> ';
	if(!empty($urlTitle)) $display .= '<a href="frame.php?url='.$urlTitle.'" class="fieldArt" target="_blank" title="'.$titleTitle.'" rel="superbox[iframe][920x920]">';
	$display .= '<span class="fieldArt">';
	if (!empty($value['bk'])){
		if(isset($_GET['s'])) $value['bk'] = highlight($value['bk']);
		$display .= $value['bk'];
	}
	if (!empty($value['bk']) and !empty($value['art'])) $display .= '; ';
	if (!empty($value['art'])) {
		if(isset($_GET['s'])) $value['art'] = highlight($value['art']);
		$display .= $value['art'];
	}
	$display .= '</span>';
	if(!empty($urlTitle)) $display .= '</a>';
	$display .= ', ';
	// Nouvelle fenêtre
	if(!empty($urlTitle)){
		$display .= '<a href="'.$urlTitle.'" class="fieldArt" target="_blank" title="'.$titleTitle.'">';
		$display .= '<img src="images/open_in_new_window.gif" alt="Nouvelle fenêtre" title="Ouvrir dans une nouvelle fenêtre"/></a>, '."\n";
	}
	// Nom Prénom auteur
	if(!empty($value['ln'])){
		$display .= '<a href="?a=on&amp;ln='.urlencode($value['ln']).'&amp;action=go" class="fieldDesc">'.$value['ln'];
		if(isset($value['fn']))  $display .= ' '.$value['fn'];
		$display .= '</a>, ';
	}
	// Revue
	if(!empty($value['jo'])){
		if(isset($_GET['s'])) $value['jo'] = highlight($value['jo']);
		$display .= '<a href="?a=on&amp;jo='.urlencode($value['jo']).'&amp;action=go" class="fieldDesc" style="font-style:italic;">'.$value['jo'].'</a>, ';
	}
	// Volume
	if(!empty($value['vo'])) $display .= $value['vo'].', ';
	// Numéro
	if(!empty($value['no'])) $display .= 'n° '.$value['no'].', ';
	// Année
	if(!empty($value['yr'])){
		if(isset($_GET['s'])) $value['yr'] = highlight($value['yr']);
		$display .= '<a href="?a=on&amp;yr='.urlencode($value['yr']).'&amp;action=go" class="fieldDesc">'.$value['yr'].'</a>, ';
	}
	// Pages
	if(!empty($value['pg'])){
		$display .= 'p. '.$value['pg'];
		if(!empty($value['pgend'])) $display .= '-'.$value['pgend'];
		$display .= ', ';
	}
	// Volume
	if(!empty($value['pb'])){
		if(isset($_GET['s'])) $value['pb'] = highlight($value['pb']);
		$display .= '<a href="?a=on&amp;pb='.urlencode($value['pb']).'&amp;action=go" class="fieldDesc">'.$value['pb'].'</a>, ';
	}
  // Détail AJAX
  $display .= '<a href="view.php" rel="superbox[ajax][view.php?bibkey='.$value['bibkey'].'][500x600]" class="fieldDesc">Détail</a>, ';
	// PDF AHP
/*	if(!empty($urlMyrl)) {
		$display .= '<a href="'.$urlMyrl.'" title="'.$titleMyrl.'" style="text-decoration:none;" rel="superbox[iframe][1000x1000]">'.$libMyrl.'</a>'."\n";
		$display .= '<a href="'.$urlMyrl.'" title="'.$titleMyrl.'" target="_blank"><img src="images/open_in_new_window.gif" alt="Nouvelle fenêtre" title="Ouvrir dans une nouvelle fenêtre"/></a>, '."\n";
	}
	// pas d'extension
	else $display .= $libMyrl."\n";
	// PDF autres archives
	if(!empty($urlUrl)){
		$display .= '<a href="'.$urlUrl.'" title="'.$titleLink.'" style="text-decoration:none;" rel="superbox[iframe][1000x1000]"><span class="pdfLogo">&nbsp;</span></a>'."\n";
		$display .= '<a href="'.$urlUrl.'" title="'.$titleLink.'" target="_blank"><img src="images/open_in_new_window.gif" alt="Nouvelle fenêtre" title="Ouvrir dans une nouvelle fenêtre"/></a>, '."\n";
	}
*/

  // BibTex
  //$display .= '<a href="bibtex.php?bibkey='.$value['bibkey'].'" onclick="window.open(this.href,\'\',\'width=400,height=450,menubar=yes,resizable=yes\'); return false;" target="_blank" class="bibtexLogo" title="Export notice en BibTeX" style="padding-right:1em;"><span style="display:none;">BibTeX</span></a>';
  // Détails
  //$display .= '<a href="view.php?bibkey='.$value['bibkey'].'" onclick="window.open(this.href,\'\',\'width=450,height=700,menubar=yes,resizable=yes\'); return false;" target="_blank" class="" title="Notice détaillée" style="padding-right: 1em;"><span >Détail</span></a>';

	$display .= "</div>\n";;
	echo $display;
}

echo '</div>';

// Barre de navigation
if(isset($navBar)) echo '<div style="text-align:center;"><span class="roundBox">'.$navBar.'</span></div>';

?>